package com.javaIO.demo2;

import java.io.*;

public class Test3 {
    public static void main(String[] args) {
        /**
         * FileReader   底层封装FileInputStream
         *  FileWriter与FileReader ------二次封装，不需要传递字节流对象
         *  字符缓冲流
         *  BufferedReader BufferedWriter    8192/1024 = 8k
         */
        try {
            String fileNameRead = "D:\\SoftDevelopment\\Java\\file\\test.txt";
            String fileNameWriter = "D:\\SoftDevelopment\\Java\\file\\demo\\test.txt";

//            FileReader fileReader = new FileReader(fileNameRead);
//            FileWriter fileWriter = new FileWriter(fileNameWriter);

            BufferedReader bufferedReader = new BufferedReader(new FileReader(fileNameRead));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileNameWriter));

            int len;
            char[] buf = new char[1024];
            while ((len = bufferedReader.read(buf)) != -1) {
                System.out.println(new String(buf, 0, len));
                //写入
                bufferedWriter.write(buf, 0, len);

            }
            bufferedReader.close();
            bufferedWriter.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
